App.service('date_access_service', ["$resource", "$http", function($resource, $http) {
    'use strict';
    var factory = {};
    factory.getListDate = function(url, params,success,error) {
        if(url == null){
            console.error("Url不能为空!");
        }else {
            var rUrl = url;
            if(params != null){
                var str = "?";
                angular.forEach(params, function (value, key) {
                    console.log(key + ':' + value);
                    str =  str + key+"="+value+"&";
                });
                str = str.substring(0,str.length-1);
                rUrl = rUrl + str;
                console.log(rUrl);
            }
            $http.get(rUrl)
                .success(function (data,status,headers,config) {
                    if(success != null){
                        success(data,status,headers,config);
                    }
                })
                .error(function(data,status,headers,config){
                    if(error != null){
                        error(data,status,headers,config);
                    }
                })
            ;
        }
    };

    factory.deleteOne = function(url,id,success,error) {
        if(url == null){
            console.error("Url不能为空!");
        }else {
            if(id != null){
                var rUrl = url + "?id="+id;
                $http.post(rUrl)
                    .success(function (data,status,headers,config) {
                        if(success != null){
                            success(data,status,headers,config);
                        }
                    })
                    .error(function(data,status,headers,config){
                        if(error != null){
                            error(data,status,headers,config);
                        }
                    });
            }else {
                console.error("id不能为空");
            }
        }
    };

    factory.addOne = function(url, params,success,error) {
        if(url == null){
            console.error("Url不能为空!");
        }else {
            var rUrl = url;
            if(params != null){
                $http.post(rUrl,params)
                    .success(function (data,status,headers,config) {
                        if(success != null){
                            success(data,status,headers,config);
                        }
                    })
                    .error(function(data,status,headers,config){
                        if(error != null){
                            error(data,status,headers,config);
                        }
                    });
            }else {
                console.error("参数不能为空！");
            }
        }
    };

    factory.getOne = function(url,id,success,error) {
        if(url == null){
            console.error("Url不能为空!");
        }else {
            var rUrl = url+'?'+'id='+id;
            if(id != null){
                $http.get(rUrl)
                    .success(function (data,status,headers,config) {
                        if(success != null){
                            success(data,status,headers,config);
                        }
                    })
                    .error(function(data,status,headers,config){
                        if(error != null){
                            error(data,status,headers,config);
                        }
                    });
            }else {
                console.error("参数不能为空！");
            }
        }
    };

    factory.updateOne = function(url,id,params,success,error) {
        if(url == null){
            console.error("Url不能为空!");
        }else {
            var rUrl = url+'?'+'id='+id;
            if(id != null && params != null){
                $http.post(rUrl,params)
                    .success(function (data,status,headers,config) {
                        if(success != null){
                            success(data,status,headers,config);
                        }
                    })
                    .error(function(data,status,headers,config){
                        if(error != null){
                            error(data,status,headers,config);
                        }
                    });
            }else {
                console.error("参数不能为空！");
            }
        }
    };
    return factory;
}]);